package MalouZoo;

import java.util.ArrayList;
import java.util.List;

public class AnimalKeeper extends User implements Keepment,DisplayKeeper{


    public AnimalKeeper(String keeperName){
        super.setUserName(keeperName);
    }
    private String keeperName;
    private Integer keeperAge;
    private List<Animal> animals = new ArrayList<>();




    //饲养员名字
    public String getKeeperName() {
        return keeperName;
    }
    public void setKeeperName(String keeperName) {
        this.keeperName = keeperName;
    }
    //饲养员年龄
    public Integer getKeeperAge() {
        return keeperAge;
    }
    public void setKeeperAge(Integer keeperAge) {
        this.keeperAge = keeperAge;
    }
    //管理动物
    public boolean addAnimal(Animal animal) {
        animals.add(animal);
        return false;
    }

    @Override
    public boolean deleteAnimal(Animal animal) {
        return this.animals.remove(animal);
    }

    @Override
    public boolean deleteAnimal(String animalName) {
        return this.animals.remove(findAnimal(animalName));
    }

    @Override
    public boolean updateAnimal(Animal oldAnimal, Animal newAnimal) {
        boolean successedRemoved = this.animals.remove(oldAnimal);
        boolean successedAdded = this.animals.add(newAnimal);
        return (successedAdded && successedRemoved);
    }

    @Override
    public Animal findAnimal(String animalName) {
        Animal foundAnimal = null;
        //用foreach循环遍历
        for( Animal animal : this.animals ){
            if (animal.getUserName().equals(animalName)) {
                foundAnimal= animal;
            }
        }
        return foundAnimal;
    }

    public void removeAnimal(Animal animal) {
        animals.remove(animal);
    }

    public List<Animal> getAnimals() {
        return animals;
    }

    @Override
    public String displayAllAnimals() {
        String displayMessage = "";
        for( Animal animal : this.animals ){
            displayMessage += animal.getUserName();
        }
        return displayMessage;
    }
}
